//
//  SCAudioVisualTableView.m
//  OurMoon
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "SCAudioVisualTableView.h"
#import "SCVideoListTableViewCell.h"
#import "NightHeader.h"
#import "SCRadioSectionModel.h"
#import "FitHeader.h"
@implementation SCAudioVisualTableView

- (instancetype)initWithFrame:(CGRect)frame WithType:(SCTableViewKind)type
{
    self = [super initWithFrame:frame];
    if (self) {
        _kind = type;
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [[UITableView alloc] init];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self addSubview:_tableView];
    }
    return self;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_kind == SCTableViewByVideo) {
        return 300 * FitHeight;
    }
    else if (_kind == SCTableViewByRadio){
        if (indexPath.row % 2 == 0) {
            return 40 * FitHeight;
        }
        else{
            return 200 * FitHeight;
        }
    }
    return 0;
}
//视频set方法
- (void)setDataVideoListArray:(NSMutableArray *)dataVideoListArray
{
    if (_kind == SCTableViewByVideo) {
        _dataVideoListArray = dataVideoListArray;
    }
    [_tableView reloadData];
}
//电台set方法
- (void)setDataRadioListArray:(NSMutableArray *)dataRadioListArray
{
    if (_kind == SCTableViewByRadio) {
        _dataRadioListArray = dataRadioListArray;
    }
    [_tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_kind == SCTableViewByVideo) {
        
        return _dataVideoListArray.count;
    }
    else if (_kind == SCTableViewByRadio){
        return _dataRadioListArray.count;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_kind == SCTableViewByVideo) {
        static NSString *identifierVideo = @"cellVideo";
        SCVideoListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierVideo];
        if (!cell) {
            cell = [[SCVideoListTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifierVideo];
        }
        cell.descriptionLabel.textType = [NSNumber numberWithInteger:LabelColorGray] ;
        [cell NightWithType:UIViewColorTypeNormal];
        [cell.descriptionLabel NightWithType:UIViewColorTypeNormal];
        cell.videoListModel = _dataVideoListArray[indexPath.row];
        cell.selectionStyle = NO;
        return cell;
    }
    
    if  (_kind == SCTableViewByRadio){
        if (indexPath.row % 2 == 0) {
            static NSString *identifierRadio1 = @"cellRadio1";
            UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:identifierRadio1];
            if (!cell1) {
                
                cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifierRadio1];
            }
            SCRadioSectionModel *radioSectionModel = [[SCRadioSectionModel alloc] init];
            radioSectionModel = _dataRadioListArray[indexPath.row];
            cell1.textLabel.text = radioSectionModel.cname;
            cell1.accessoryType = 1;
            [cell1 NightWithType:UIViewColorTypeNormal];
            [cell1.textLabel NightWithType:UIViewColorTypeNormal];
            cell1.selectionStyle = NO;
            return cell1;
        }
        else{
            static NSString *identifierRadio2 = @"cellRadio2";
            SCRadioListTableCell *cell2 = [tableView dequeueReusableCellWithIdentifier:identifierRadio2];
            if (!cell2) {
                cell2 = [[SCRadioListTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifierRadio2];
            }
            cell2.delegate = self;
            cell2.dataArray = _dataRadioListArray[indexPath.row];
            cell2.selectionStyle = NO;
            return cell2;
        }
    }
    
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_kind == SCTableViewByVideo){
        [self.delegate VideoPlayViewControllerJump:_dataVideoListArray[indexPath.row]];
    }
    if (_kind == SCTableViewByRadio) {
        [self.delegateMoreRadio RadioMoreViewControllerJump:_dataRadioListArray[indexPath.row]];
    }
}
- (void)RadioJumpPLayDetail:(SCRadioModel *)radioModel
{
     if  (_kind == SCTableViewByRadio)
     {
         [self.delegateRadio RadioPlayViewControllerJump:radioModel];
     }
}
@end
